import { JudgmentAPI } from '../index'
import { get, post, put, del } from '@/utils/request'

export interface Judgment {
  id: string
  soulId: string
  previousLife: string
  crimes: string[]
  punishment: string
  merit: number
  judge: string
  time: string
  status: 'pending' | 'processing' | 'completed'
  result: string
  evidence?: string[]
  type: 'heaven' | 'hell' | 'reincarnate'
  duration: number
  reason: string
  remarks: string
  soul: {
    name: string
    gender: 'male' | 'female'
    age: number
    birthDate: string
    deathDate: string
    birthplace: string
    deeds: Array<{
      id: string
      time: string
      type: 'good' | 'bad'
      description: string
      merit: number
    }>
  }
}

export interface JudgmentStats {
  total: number
  pending: number
  processing: number
  completed: number
  todayCount: number
  weeklyTrend: {
    date: string
    count: number
  }[]
  heavenCount: number
  hellCount: number
  reincarnateCount: number
}

export interface JudgmentParams {
  page?: number
  pageSize?: number
  status?: string
  judge?: string
  startTime?: string
  endTime?: string
  keyword?: string
}

export interface CreateJudgmentParams {
  soulId: string
  previousLife: string
  crimes: string[]
  punishment: string
  merit: number
  evidence?: string[]
  type: 'heaven' | 'hell' | 'reincarnate'
  duration: number
  reason: string
  remarks?: string
}

export interface UpdateJudgmentParams {
  punishment?: string
  merit?: number
  status?: string
  result?: string
  evidence?: string[]
  type?: 'heaven' | 'hell' | 'reincarnate'
  duration?: number
  reason?: string
  remarks?: string
}

export const JudgmentService = {
  async getJudgments(params: JudgmentParams): Promise<{
    total: number
    items: Judgment[]
  }> {
    return get(JudgmentAPI.list, params)
  },

  async getJudgment(id: string): Promise<Judgment> {
    return get<Judgment>(JudgmentAPI.get(id))
  },

  async getStats(): Promise<JudgmentStats> {
    return get<JudgmentStats>(JudgmentAPI.stats)
  },

  async createJudgment(params: CreateJudgmentParams): Promise<Judgment> {
    return post<Judgment>(JudgmentAPI.create, params)
  },

  async updateJudgment(id: string, params: UpdateJudgmentParams): Promise<Judgment> {
    return put<Judgment>(JudgmentAPI.update(id), params)
  },

  async deleteJudgment(id: string): Promise<void> {
    return del(JudgmentAPI.delete(id))
  },
}
